#pragma once
#ifndef _FORT_DIRECTX_H
#define _FORT_DIRECTX_H

#include <windows.h>

#include <d3d11.h>

#include <system/Platform.h>
#include <graphics/d3d11/Mesh.h>



namespace fort
{
	class WindowWin32;
	class Mesh;
	class Platform;


	class D3D11 : public Platform
	{
	public:
		D3D11(HINSTANCE hinstance, UInt32 width, UInt32 height, bool fullscreen, bool vsync_enabled, bool test);
		~D3D11();
		void Resize(UInt32 width, UInt32 height);
		
		void Clear(const bool clear_render_target, const bool clear_depth_buffer, const bool clear_stencil_buffer) const;


		void BeginScene() const;
		void EndScene() const;


		void PreRender();
		void PostRender();
		void Clear() const;

		bool Update();
		float GetFrameTime();

		//Mesh* CreateMesh() const;

		inline ID3D11Device* Device() const { return device; } 
		inline ID3D11DeviceContext* deviceContext() const { return device_context; }
		inline WindowWin32* Window() const { return window; }
	private:
		//RenderTarget* CreateRenderTarget(const Int32 width, const Int32 height) const;

		void Release();
		bool InitDeviceAndSwapChain(bool fullscreen);
		void CompileShaders();
		void ReleaseDeviceAndSwapChain();

		WindowWin32* window;
		UInt64	clock_last_frame;
		D3D_DRIVER_TYPE driver_type;
		ID3D11Device* device;
		ID3D11DeviceContext* device_context;
		IDXGISwapChain* swap_chain;
		ID3D11Texture2D* back_buffer;
		ID3D11RenderTargetView* render_target_view;
		ID3D11Texture2D* depth_stencil;
		ID3D11DepthStencilView* depth_stencil_view;
		bool vsync_enabled;
	};
}
#endif // _ABFW_PLATFORM_D3D11_H
